﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using MixScript.Appl.Security;
namespace MixScriptWeb.Member
{
    public partial class Logon : cCommonWeb// System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //txtUser.Text = "yanusapu";
                //txtUserPass.Text = "password";
                //txtUser.Text = "coba";
                //txtUserPass.Text = "coba123";
            }
            catch (Exception ex)
            {

                throw;
            }

        }
        void ResetProperty()
        {
            setLabelColor(new Label[] { lbUSer, lbUSerPass }, Color.Black);
            statusbar.Visible = false;
        }



        private bool isvalid()
        {
            ResetProperty();
            if (txtUser.Text.Trim() == string.Empty)
            {
                lbUSer.ForeColor = Color.Red;
                throw new Exception("User IDName must be filled");
            }
            if (txtUserPass.Text.Trim() == string.Empty)
            {
                lbUSerPass.ForeColor = Color.Red;
                throw new Exception("Password must be filled");
            }
            return true;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (isvalid())
                {

                    cSecurity oSec = new cSecurity();
                    bool bchangepass;
                    if (oSec.DoLogin(txtUser.Text, txtUserPass.Text, out bchangepass))
                    {
                        if (bchangepass)
                        {
                            //txtUID.Enabled = false;
                            //MessageBox.Show("Silahkan mengganti password terlebih dahulu");
                            //new cCommon().VisibilityControl(true, lblConfirm, txtConfirm);
                            //txtUPass.Text = "";
                            //btnExit.Text = "Back";
                            //btnLogin.Text = "Save";
                            //txtUPass.Focus();
                        }
                        else
                        {

                            oSec.BAuth = true;
                            Session["userid"] = txtUser.Text.ToUpper();
                            Response.Redirect("/welcome.html");
                            //isexit = false;
                            //this.Close();
                        }

                    }
                    else
                    {
                        lblError.Text = "Login Gagal";
                        statusbar.Visible = true;

                    }
                }               

                //statusbar.lbl
            }

            catch (Exception ex)
            {

             //statusbar.lblErr
                lblError.Text = ex.Message;
                statusbar.Visible = true;
            }
            
        }
    }
}